<template>
  <div class="jsbos-common-layout">
    <div class="jsbos-common-layout-center">
      <el-row class="jsbos-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="6">
            <el-form-item label="考试名称">
              <el-input
                v-model="query.fullName"
                placeholder="请输入"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="状态">-->
          <!--              <el-select v-model="query.reviewStatus" placeholder="请选择" clearable>-->
          <!--                <el-option-->
          <!--                  v-for="(item, index) in enabledMarkOptions"-->
          <!--                  :key="index"-->
          <!--                  :label="item.fullName"-->
          <!--                  :value="item.id"-->
          <!--                  :disabled="item.disabled"-->
          <!--                ></el-option>-->
          <!--              </el-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()"
                >查询</el-button
              >
              <el-button icon="el-icon-refresh-right" @click="reset()"
                >重置</el-button
              >
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="jsbos-common-layout-main jsbos-flex-main">
        <div class="jsbos-common-head">
          <div class="jsbos-common-head-right">
            <div>
              <!-- 按钮 -->
            </div>
            <el-tooltip effect="dark" content="刷新" placement="top">
              <el-link
                icon="icon-ym icon-ym-Refresh JSBOS-common-head-icon"
                :underline="false"
                @click="reset()"
              />
            </el-tooltip>
            <screen-full isContainer />
          </div>
        </div>
        <el-table
          v-loading="listLoading"
          :data="list"
          ref="jsbosTableRef"
          @sort-change="sortChange"
        >
          <el-table-column
            prop="fullName"
            label="考试名称"
            width="0"
            align="left"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            prop="examPaperId"
            label="试卷名称"
            width="0"
            align="left"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            prop="startDatetime"
            label="开始时间"
            min-width="150"
            align="left"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            prop="endDatetime"
            label="截至时间"
            min-width="150"
            align="left"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            prop="reviewNum"
            label="未批阅/总批阅"
            min-width="100"
            align="left"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">{{
              getReviewNum(scope.row)
            }}</template>
          </el-table-column>
          <el-table-column
            label="批阅状态"
            min-width="100"
            prop="enabledMark"
            algin="left"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">{{
              scope.row.enabledMark | dynamicText(enabledMarkOptions)
            }}</template>
          </el-table-column>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click="goDetail(scope.row.id, scope.row.fullName)"
                >详情</el-button
              >
              <el-button type="text" @click="reviewHandle(scope.row.taskList)"
                >批阅</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="listQuery.currentPage"
          :limit.sync="listQuery.pageSize"
          @pagination="initData"
        />
      </div>
    </div>

    <edit ref="edit"></edit>
    <!-- <record ref="record" ></record> -->
    <record v-if="detailVisible" ref="Detail" @refresh="closeRecord"></record>
  </div>
</template>

<script>
import { getReviewList } from "@/views/exam/api/manager";
import edit from "./edit";
import record from "./record";

export default {
  name: "reviewIndex",
  components: { record, edit },
  data() {
    return {
      query: {
        fullName: undefined,
        startDatetime: undefined,
        creatorUserId: undefined,
        reviewStatus: undefined,
      },
      detailVisible: false,
      list: [],
      listLoading: true,
      total: 0,
      listQuery: {
        enabledMark: "1",
        keyword: "",
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "",
      },
      enabledMarkOptions: [
        { fullName: "待批阅", id: "0" },
        { fullName: "已批阅", id: "1" },
      ],
    };
  },
  computed: {
    menuId() {
      return this.$route.meta.modelId || "";
    },
  },
  created() {
    this.initData();
  },
  methods: {
    // torecord(id) {
    //   console.log("id========>", id);

    //   this.formVisible = true;
    //   this.$nextTick(() => {
    //     this.$refs.edit.init(id);
    //   });
    // },
    getReviewNum(row) {
      return row.noReviewNum + "/" + row.reviewNum;
    },
    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.initData();
    },
    initData() {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query,
        menuId: this.menuId,
      };
      getReviewList(_query).then((res) => {
        var _list = [];
        for (let i = 0; i < res.data.list.length; i++) {
          let _data = res.data.list[i];
          _list.push(_data);
        }
        this.list = _list;
        this.total = res.data.pagination.total;

        this.listLoading = false;
      });
    },
    reviewHandle(arr) {
      this.formVisible = true;
      this.$nextTick(() => {
        this.$refs.edit.init(arr);
      });
    },
    goDetail(id, name) {
      this.detailVisible = true;
      this.$nextTick(() => {
        this.$refs.Detail.initParam(id, name);
      });
    },
    closeRecord() {
      this.detailVisible = false;
    },
    search() {
      this.initData();
    },
    refresh(isrRefresh) {
      if (isrRefresh) this.reset();
    },
    resetListQuery() {
      this.listQuery = {
        enabledMark: "1",
        keyword: "",
        currentPage: 1,
        pageSize: 20,
        sort: "asc",
        sidx: "",
      };
    },
    resetQuery() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
    },
    reset() {
      this.resetListQuery();
      this.resetQuery();
      this.search();
    },
  },
};
</script>
